<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="com.beaut.project.util.FlowUtility"%>
<%@ include file="/public/header.jsp"%>

<html>
<head>
<title>工单人员变更</title>
</head>
<script type="text/javascript">
		$(function(){
			$("#searchValue").keypress(function(e) { 
		    	// 回车键事件 
		     	if(e.which == 13) { 
		     		 doSearch();
		       	} 
		   	}); 
			$("#searchValue3").keypress(function(e) { 
		    	// 回车键事件 
		     	if(e.which == 13) { 
		     		 doSearch3();
		       	} 
		   	}); 
			$('#gd_status').combobox({
				 url:'<%=contextPath%>/springMVC/gd/listGDStatus',
				 valueField:'id',
				 textField:'text',
				 onChange:function(){
						doSearch();
					}
			});
			$("#dept_id").combotree({
				url:'<%=contextPath %>/springMVC/group/listDepartment',
				method:'POST',
				animate:true,
				lines:true,
				onChange:function(){
					doSearch();
				}
			});
			jQuery("#searchValue2").keypress(function(e) { 
		    	// 回车键事件 
		     	if(e.which == 13) { 
		     		 doSearch2();
		       	} 
		   	}); 
			jQuery('#gd_admin_id').combogrid({
				title:'派单人选择',
				mode:"remote",
				loadMsg:'正在加载数据，请稍后......',
				panelWidth:550,
				panelHeight:400,
				url:"<%=contextPath%>/springMVC/group/listPageUser",
				idField:"id",
				textField:"truename",
				rownumbers:true,
				fitColumns:true,
				columns: [[
					{field:'id',hidden:true},
					{field:'deptId',hidden:true},
					{field:'truename',title:'姓名',width:100},
					{field:'deptName',title:'所属部门',width:100},
					{field:'privName',title:'角色',width:100}
				]],
				toolbar:"#tba",
				pageSize:10,
				pageList:[10,50,100],  
				pagination:true,
				onChange:function(){
					doSearch();
				}
			});
			jQuery("#p_dept_id").combotree({
				url:'<%=contextPath %>/springMVC/group/listDepartment',
				method:'POST',
				animate:true,
				lines:true,
				onChange:function(){
					doSearch2();
				}
			});
			$("#table").datagrid({
				title:"工单管理员变更",
				iconCls:'icon-edit',
				loadMsg:'正在加载数据，请稍后......',
				url:'<%=contextPath%>/springMVC/gd/listPageGDBase?flagType=8',
				rownumbers:true,
				fitColumns:true,
				idField:'id',
				frozenColumns:[[
					{field:'ck',checkbox:true},
					{title:'主键',field:'id',hidden:true},
					 {title:'所属部门id',field:'dept_id',hidden:true}
				]],
				columns:[[
					{title:'工单状态',field:'gd_status',hidden:true},
					{title:'工单进度',field:'gd_status_desc',width:80,align:'center'},
					{title:'派单人',field:'gd_admin_name',width:80,align:'center'},
					{title:'所属部门',field:'dept_name',width:100,align:'center'},
					{title:'工单编号',field:'gd_code',width:100,align:'center'},
					{title:'工单名称',field:'gd_name',width:100,align:'center'}
				]],
				view: detailview,
				detailFormatter:function(index,row){
					return '<div style="padding:2px"><table class="ddv"></table></div>';
				},
				onExpandRow: function(index,row){
					var gd_id = row.id;
					var gd_status = row.gd_status;
					var gd_content_num = row.gd_content_num;
					var ddv = $(this).datagrid('getRowDetail',index).find('table.ddv');
					 ddv.datagrid({
						title:'内容明细',
						url:'<%=contextPath%>/springMVC/gd/listGDContent?gd_id='+gd_id,
						loadMsg:'正在加载数据，请稍后......',
						fitColumns:true,
						rownumbers:true,
						columns:[[
							{title:'内容id',field:'id',hidden:true},
							{title:'编号',field:'gd_content_code',hidden:true},
							{title:'',field:'desc',width:100,align:'center',formatter:function(value,row){
								
								if(row.gd_content_code == '1'){
									return "原始内容";
								}else{
									return "第"+(row.gd_content_code-1)+"次变更内容";
								}
							}},
							{title:'工单内容',field:'content',width:150,align:'center'},
							{title:'工时',field:'gd_total_time',width:50,align:'center'},
							{title:'要求日期（起始）',field:'gd_start',width:100,align:'center'},
							{title:'要求日期（截止）',field:'gd_will_end',width:100,align:'center'},
							{title:'收单单位',field:'gd_worker_name',width:100,align:'center'}
							]],
					 	onResize:function(){
					        $('#table').datagrid('fixDetailRowHeight',index);
					    },
					 	onLoadSuccess:function(){
					       setTimeout(function(){
					         $('#table').datagrid('fixDetailRowHeight',index);
					       },0);
					   }
					 });
					 $('#table').datagrid('fixDetailRowHeight',index);
				},
				toolbar:"#tb",
				pageSize:10,
				pageList : [10,50,100],  
				pagination:true,
				onLoadSuccess:function(rtJson){
					if(rtJson.rtState== '1')
					{
						$.messager.alert('提示',rtJson.rtMsrg);
					}
				}
			});
		});
		 
		function gdBgPerson(){
			var dept_id = $("#dept_id").combotree('getValue');
			var gd_admin_id = jQuery("#gd_admin_id").combotree('getValue');
			if((dept_id==""||dept_id==null)&&(gd_admin_id==""||gd_admin_id==null)){
				jQuery.messager.alert('提示','请选择工单管理员或者所属部门!');  
				return ;
			}
			var rows=jQuery('#table').datagrid('getSelections');
			var arrGdIds="";
			var dept_id="";
			if(rows.length==0)
			{
				jQuery.messager.alert('提示','选中要变更人员的工单');  
				return ;
			}
			for(var i=0;i<rows.length;i++)
			{
				if(i==(rows.length-1))
				{
					arrGdIds+=rows[i].id;
				}else
				{
					arrGdIds+=rows[i].id+",";
				}
				dept_id=rows[i].dept_id;
				jQuery("#gd_admin_name").val(rows[i].gd_admin_name);
			}
			jQuery.messager.confirm('确认','您确认变更这些工单的管理员吗？',function(msg){
				if(msg){
					jQuery('#dd').dialog({
				        title: '请选择工单管理员',
				        width: 200,
				        height: 120,
				        top:130,
				        closed: false,
				        cache: false,
				        href: '',
				        modal: true
				        });
					jQuery("#dd").show();
					jQuery("#arrGdIds").val(arrGdIds);
					jQuery('#gd_admin_id2').combogrid({
						title:'派单人选择',
						mode:"remote",
						loadMsg:'正在加载数据，请稍后......',
						panelWidth:550,
						panelHeight:400,
						url:"<%=contextPath%>/springMVC/group/listPageUser?dept_id="+dept_id,
						idField:"id",
						textField:"truename",
						rownumbers:true,
						fitColumns:true,
						columns: [[
							{field:'id',hidden:true},
							{field:'deptId',hidden:true},
							{field:'truename',title:'姓名',width:100},
							{field:'deptName',title:'所属部门',width:100},
							{field:'privName',title:'角色',width:100}
						]],
						toolbar:"#tba2",
						pageSize:10,
						pageList:[10,50,100],  
						pagination:true	,
						onChange:function(){
							var row = jQuery('#gd_admin_id2').combogrid("grid").datagrid('getSelected');
							if(row != null){
								jQuery("#gdAdminId").val(row.id);
								jQuery("#gdAdmin").val(row.truename);
							}
							
						}
					});
				}
			});
		}
		function rtCallBack(){
			$('#table').datagrid('reload');
		}
			
		function doSearch3() {
			var searchValue = jQuery('#searchValue3').val();
			jQuery('#gd_admin_id2').combogrid("grid").datagrid('load', {
				searchValue : searchValue
			});
		}
		function doSearch2() {
			var searchValue = jQuery('#searchValue2').val();
			var dept_id = $("#p_dept_id").combotree('getValue');
			jQuery('#gd_admin_id').combogrid("grid").datagrid('load', {
				searchValue : searchValue,
				dept_id:dept_id
			});
		}
	function doSearch() {
		var searchValue = $('#searchValue').val();
		var dept_id = $("#dept_id").combotree('getValue');
		var gd_admin_id = jQuery("#gd_admin_id").combotree('getValue');
		$('#table').datagrid('load', {
			searchValue : searchValue,
			dept_id : dept_id,
			gd_admin_id:gd_admin_id
		});
	}
	function closeBg(){
		jQuery('#dd').dialog("close"); 
	}
	function submitBg(){
		var arrGdIds=jQuery('#arrGdIds').val();
		var gdAdmin=jQuery('#gdAdmin').val();
		var gdAdminId=jQuery('#gdAdminId').val();
		var gd_admin_name=jQuery('#gd_admin_name').val();
		jQuery.messager.confirm('确认','您确定要将人员'+gd_admin_name+'变更为'+gdAdmin+'吗？',function(msg){
			if(msg){
				jQuery.ajax({
					type:'POST',
					url:"<%=contextPath %>/springMVC/group/updateGdPerson",
					data:"ids="+arrGdIds+"&gdAdminId="+gdAdminId+"&gdAdmin="+gdAdmin,
					dataType:"json",
					success:function(rtJson){
						if(rtJson.rtState == '0'){
							warningInfo(rtJson.rtMsrg);
							table_reload(rows.length);
							
						}
						else{
						jQuery.messager.alert('提示：',rtJson.rtMsrg);
						}
					}
				});
			}
		});
	}
	
</script>
<body style="height: 97%">
	<div id="table" data-options="fit:true"></div>
	<div id="tb" style="padding:3px;height:auto">
	<div style="float:left;">
				<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="gdBgPerson();">人员变更</a>
			</div>
		<div align="right">
			派单人：<input type="text" id="gd_admin_id" name="gd_admin_id"   style="width:100px"> &nbsp;&nbsp;
			所属部门：<input  id="dept_id" name="dept_id" class="easyui-combotree">&nbsp;&nbsp;
			工单编号/名称：<input id="searchValue" name="searchValue" style="width:150px" title="工单编号/名称" placeholder="工单编号/名称 "/>&nbsp;&nbsp; 
			<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-search',plain:true" onclick="doSearch();"></a>
		</div>
	</div>
	<div id="tba" style="padding:3px;height:auto">
			<div align="right">
			             所属部门：<input  id="p_dept_id" name="p_dept_id"  style="width:150px"  class="easyui-combotree">
				查询条件：<input id="searchValue2" name="searchValue2" style="width:150px" placeholder="用户名称或者用户真实姓名"/>
				<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-search',plain:true" onclick="doSearch2();"></a>
			</div>
		</div>
		<div id="tba2" style="padding:3px;height:auto">
			<div align="right">
				查询条件：<input id="searchValue3" name="searchValue3" style="width:150px" placeholder="用户名称或者用户真实姓名"/>
				<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-search',plain:true" onclick="doSearch3();"></a>
			</div>
		</div>
		<div id="dd" >
		<div style="text-align:center;">
					<br>
					<input type="text" id="gd_admin_id2" name="gd_admin_id2"  data-options="required:true">
					<input type="hidden" id="arrGdIds" name="arrGdIds"  >
					<input type="hidden" id="gdAdmin" name="gdAdmin"  >
					<input type="hidden" id="gdAdminId" name="gdAdminId"  >
					<input type="hidden" id="gd_admin_name" name="gd_admin_name"  >
					<br><br>
		<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-save',plain:false" onclick="submitBg();">提交</a>
		<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-cancel',plain:false" onclick="closeBg();">关闭</a>
		</div>
		</div>
</body>
</html>
